import json
import os

def parse_consume_json():
    json_path = 'c:\\Users\\Administrator\\RuoYi-Vue01\\python_project\\consume_content.json'
    
    try:
        with open(json_path, 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        print("=== consume_content.json 解析结果 ===")
        print(f"总共有 {len(data)} 个标签类别：")
        
        for category_name, rules_list in data.items():
            print(f"\n类别名称: {category_name}")
            print(f"  包含 {len(rules_list)} 个标签规则：")
            
            for rule in rules_list:
                label = rule.get('label', '无标签名称')
                rules_text = rule.get('rules', '无规则')
                comment = rule.get('comment', '无注释')
                print(f"    - 标签: {label}")
                print(f"      规则: {rules_text}")
                if comment != '无注释':
                    print(f"      注释: {comment}")
        
        return data
        
    except Exception as e:
        print(f"解析JSON文件出错: {e}")
        # 尝试使用其他编码读取
        try:
            with open(json_path, 'r', encoding='gbk') as f:
                data = json.load(f)
            print("使用GBK编码成功读取")
            return data
        except Exception as e2:
            print(f"使用GBK编码读取也失败: {e2}")
            return None

if __name__ == "__main__":
    parse_consume_json()